<?php
/**
 * @title 187. 重复的DNA序列 - 哈希
 * @author start2004
 */

// ini_set("memory_limit", "128M");

class Solution {

    /**
     * @param String $s
     * @return String[]
     */
    function findRepeatedDnaSequences($s) {
        /**
         * @since 2020-08-11 结果集
         */
        $result = [];

        /**
         * @since 2020-08-11 哈希
         */
        $hashs = [];

        /**
         * @since 2020-08-11 字符串长度
         */
        $len = strlen($s);

        /**
         * @since 2020-08-11 穷列
         */
        for ($i=0; $i<=$len-10; $i++){
            $chars = substr($s, $i, 10);

            /**
             * @since 2020-08-11 是否存在
             */
            if(isset($hashs[$chars])){
                $hashs[$chars] += 1;

                /**
                 * @since 2020-08-11 出现超过1次
                 */
                if($hashs[$chars] == 2){
                    $result[] = $chars;
                } else {}
            } else {
                $hashs[$chars] = 1;
            }
        }

        /**
         * @return
         */
        return $result;
    }
}



/**
 * @url http://127.0.0.1/leetcode/202008/2020.08.11_6.php
 */
$datas = [
    "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT",
];

include_once dirname(__DIR__) . DIRECTORY_SEPARATOR ."xhprof.php";
$xhprof = new Xhprof();
foreach ($datas as $data){
    var_dump($data);

    $obj = new Solution();
    $result = $obj->findRepeatedDnaSequences($data);
    var_dump($result);
    echo str_repeat("<br>", 3);
}
$xhprof->end();
